package com.example.designpatterns.project.rate;

import java.util.List;

/**
 * Created by zyy on 2022/1/12.
 * RuleConfig 类嵌套了另外两个类 AppRuleConfig 和 ApiLimit。
 *
 *
 *
 configs:          <!--对应RuleConfig-->
 - appId: app-1    <!--对应AppRuleConfig-->
     limits:
     - api: /v1/user <!--对应ApiLimit-->
         limit: 100
         unit：60
     - api: /v1/order
         limit: 50
 - appId: app-2
     limits:
     - api: /v1/user
         limit: 50
     - api: /v1/order
         limit: 50
 *
 */


public class RuleConfig {
    private List<AppRuleConfig> configs;

    public List<AppRuleConfig> getConfigs() {
        return configs;
    }

    public void setConfigs(List<AppRuleConfig> configs) {
        this.configs = configs;
    }

    public static class AppRuleConfig {
        private String appId;
        private List<ApiLimit> limits;

        public AppRuleConfig() {}

        public AppRuleConfig(String appId, List<ApiLimit> limits) {
            this.appId = appId;
            this.limits = limits;
        }
        //...省略getter、setter方法...
    }
}

//class ApiLimit {
//    private static final int DEFAULT_TIME_UNIT = 1; // 1 second
//    private String api;
//    private int limit;
//    private int unit = DEFAULT_TIME_UNIT;
//
//    public ApiLimit() {}
//
//    public ApiLimit(String api, int limit) {
//        this(api, limit, DEFAULT_TIME_UNIT);
//    }
//
//    public ApiLimit(String api, int limit, int unit) {
//        this.api = api;
//        this.limit = limit;
//        this.unit = unit;
//    }
//    // ...省略getter、setter方法...
//}

